﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Extensions.UnitTests.UriExtensionsTests
{
    [TestClass]
    public class GetQueryParametersTests
    {
        [TestMethod]
        public void GetQueryParameters_gets_querystring_parameters_from_the_given_url()
        {
            const string url = "http://some.url?key1=value1&key2=value2&key3=value3";
            IDictionary<string, string> expectedResults = new Dictionary<string, string>
                {
                    {"key1", "value1"},
                    {"key2", "value2"},
                    {"key3", "value3"},
                };

            var uri = new Uri(url);
            var results = uri.GetQueryParameters();

            Assert.AreEqual(expectedResults.Count, results.Count);

            foreach (var expectedResult in expectedResults)
            {
                Assert.IsTrue(results.Keys.Contains(expectedResult.Key));
                Assert.AreEqual(results[expectedResult.Key], expectedResults[expectedResult.Key]);
            }
        }

        [TestMethod]
        public void GetQueryParameters_gets_querystring_parameters_from_the_given_url_with_forward_slash()
        {
            const string url = "http://some.url/?key1=value1&key2=value2&key3=value3";
            IDictionary<string, string> expectedResults = new Dictionary<string, string>
                {
                    {"key1", "value1"},
                    {"key2", "value2"},
                    {"key3", "value3"},
                };

            var uri = new Uri(url);
            var results = uri.GetQueryParameters();

            Assert.AreEqual(expectedResults.Count, results.Count);

            foreach (var expectedResult in expectedResults)
            {
                Assert.IsTrue(results.Keys.Contains(expectedResult.Key));
                Assert.AreEqual(results[expectedResult.Key], expectedResults[expectedResult.Key]);
            }
        }
    }
}